import PostList from "@/components/posts/posts-list";
import { fetchPostsByPnameorcon } from "@/prisma/queries/posts";
import { redirect } from "next/navigation";

interface SearchPageProps {
  searchParams: Promise<{
    pnameorcon: string;
  }>;
}

export default async function SearchPage({ searchParams }: SearchPageProps) {
  const { pnameorcon } = await searchParams;
  if (!pnameorcon) {
    redirect("/");
  }
  const posts = await fetchPostsByPnameorcon(pnameorcon);
  return  <PostList posts={posts} />
}